<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
  function selectSort(arr){
     if(arr.length < 2 || arr == null) return 

    for(let i = 0; i < arr.length - 1; i++) {
      let min = i
      for(let j = i + 1; j < arr.length; j++) {
         min = arr[j] < arr[min] ? j : min
      }
      swap(arr,i,min)
    }
  }

// 方法1
  function swap(arr,a,b){
    let temp = arr[a]
    arr[a] = arr[b]
    arr[b] = temp
  }

// 方法2
function swap2(arr,a,b) {
  arr[a] = arr[a] ^ arr[b]
  arr[b] = arr[a] ^ arr[b]
  arr[a] = arr[a] ^ arr[b]
}

  // test
  let arr =[1,3,5,6,9,7,2,5,7]
  selectSort(arr)
console.log(arr);
  </script>
</body>
</html>